package com.huatai.datacenter.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: ht-system
 * @description: redisson配置
 * @author: songxiude
 * @create: 2023-02-10 10:31
 **/
@Configuration
public class RedissonConfig {

	@Autowired
	private RedisProperties redisProperties;

	@Bean
	public RedissonClient redissonClient() {
		Config config = new Config();
		String redisUrl = String.format("redis://%s:%s", redisProperties.getHost() + "", redisProperties.getPort() + "");
		config.useSingleServer().setAddress(redisUrl).setPassword(redisProperties.getPassword());
		config.useSingleServer().setDatabase(redisProperties.getDatabase());
		return Redisson.create(config);
	}

}
